#include<iostream>
#include<string>
#include<map>
using namespace std;
const int N = 1e5 + 10;
int s[N];
int n;
map<int, int>mp;
int main()
{
	cin >> n;
	string a;
	cin >> a;
	for (int i = 1; i <= n; i++) {
		if (a[i - 1] == '1') {
			s[i] = s[i - 1] + 1;
		}
		else {
			s[i] = s[i - 1] - 1;
		}
	}
	if (s[n] == n || s[n] == -n) {
		cout << 0 << endl;
		return 0;
	}
	int ma = -100;
	for (int i = 1; i <= n; i++) {
		mp[s[i]] = i;
	}
	for (int i = 0; i <= n - 1; i++) {
		if (mp[s[i]] > i) {
			ma = max(mp[s[i]] - i, ma);
		}
	}
	/*for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (s[i] == s[j]) {
				int idx = i - j ;
				ma = max(ma, idx);
			}
		}
	}*/
	cout << ma << endl;
	return 0;
}